package com.example.ResumeWorkPlatform;

import java.io.File;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;





/**
 * @ClassName: CleanTimer
 * @Description: 定时器任务
 * @Copyright: smartlab411
 * @Author wangfuxin
 * @DateTime 2020-09-06 12:55:58 
 */
@Component
@EnableScheduling
public class CleanTimer {
	
	private static final Logger log = LoggerFactory.getLogger(CleanTimer.class);
	
	
	/**
	 * @Title: scanCertificatesOverdue 
	 * @Description: 1.清理内存 2.清理缓存文件
	 * @Exception: 
	 * @Author wangfuxin
	 * @DateTime 2020-09-06 12:55:49
	 * @throws Exception void
	 */
	@Async
	@Scheduled(cron = "0 0 0 * * ? ")
	public void scanCertificatesOverdue() throws Exception {
		/********************* 清理内存 *******************/
		log.info(" 开始清理内存");
		System.gc();
		log.info(" 清理内存完成");
		/******************** 清理缓存文件 *******************/
		log.info(" 开始清理缓冲文件");
		File dir = new File(FilePath.CACHE_PATH);
		File[] list = dir.listFiles();
		for (File f : list) {
			long nametime = f.lastModified();
			long time = System.currentTimeMillis() - 24 * 60 * 60 * 1000;
			if (time > nametime) {
				f.delete();
			}
		} 
		log.info(" 清理缓冲文件完成");
	}
	
	
}
